import { BasicColumn, FormSchema } from '/@/components/Table';
import { Tag } from "ant-design-vue";
import { h } from "vue";
import { uploadApi } from '/@/api/sys/upload';

export const columns: BasicColumn[] = [
  {
    title: '客户名称',
    dataIndex: 'name',
    align: 'left',
  },
  {
    title: '地址',
    dataIndex: 'addressList',
    width: 180,
    align: 'left',
    customRender: ({ record }) => {
      const data = record.addressList[0];
      if (data)
        return data.name;
      return '';
    },
  },
  {
    title: '联系人及电话',
    dataIndex: 'managerList',
    align: 'left',
    customRender: ({ record }) => {
      const data = record.managerList[0];
      if (data) {
        const tag1 = h(Tag, { color: 'green' }, data.name)
        const tag2 = h(Tag, { color: 'green' }, data.tel)
        const result = h('span', [tag1, tag2]);
        return result;
      }
      return '';
    },
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    align: 'left',
  },
];


export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '关键字',
    component: 'Input',
    componentProps: {
      placeholder: '请输入客户名称',
    },
    labelWidth: 60,
    colProps: { span: 6, lg: { span: 6, offset: 0 }, sm: { span: 10, offset: 0 }, xs: { span: 16, offset: 0 } },
  },
];

//表单新增
export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '客户名称',
    required: true,
    component: 'Input',
    rules: [
      {
        required: true,
        whitespace: true,
        message: '名称不能为空！',
      },
      {
        max: 64,
        message: '字符长度不能大于64！',
      },
    ],
    colProps: { span: 24 },
  },
  {
    field: 'managerList',
    label: '联系人',
    component: 'Input',
    slot: 'managerList',
  },
  {
    field: 'addressList',
    label: '地址',
    component: 'Input',
    slot: 'addressList',
  },
  {
    field: 'bankInfoList',
    label: '开票资料',
    component: 'Input',
    slot: 'bankInfoList',
  },
  {
    field: 'fileList',
    label: '附件',
    component: 'Upload',
    colProps: { span: 24 },
    componentProps: {
      api: uploadApi,
    },
  },

  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    rules: [
      {
        max: 1024,
        message: '字符长度不能大于1024！',
      },
    ],
    colProps: { span: 24 },
  },
];

//联系人新增
export const managerSchema: FormSchema[] = [
  {
    field: 'name',
    label: '姓名',
    component: 'Input',
    colProps: { span: 24 },
    required: true,
  },
  {
    field: 'position',
    label: '职务',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'tel',
    label: '电话',
    component: 'Input',
    colProps: { span: 24 },
  },
]

//地址新增
export const addressSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    colProps: { span: 24 },
    required: true,
  },
]

//开票信息列表
export const bankInfoColumns: BasicColumn[] = [
  {
    title: '发票抬头',
    dataIndex: 'title',
  },
  {
    title: '企业地址',
    dataIndex: 'address',
  },

];
//开票信息新增
export const bankInfoSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'title',
    label: '发票抬头',
    required: true,
    component: 'Input',
    rules: [
      {
        required: true,
        whitespace: true,
        message: '发票抬头不能为空！',
      }
    ],
    colProps: { span: 24 },
  },
  {
    field: 'companyNo',
    label: '纳税人识别号',
    required: true,
    component: 'Input',
    rules: [
      {
        required: true,
        whitespace: true,
        message: '纳税人识别号不能为空！',
      }
    ],
    colProps: { span: 24 },
  },
  {
    field: 'address',
    label: '企业地址',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'tel',
    label: '联系电话',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'bankName',
    label: '开户银行',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'bankNo',
    label: '银行卡号',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: '0',
    component: 'Input',
    label: ' ',
    colProps: {
      span: 6,
    },
    slot: 'bankinfo_add',
  },
];



